9 years ago (Jul 17, 2015) | 2,871 views |
Java program source code for multiplying 2 Matrix
Category: Java Programming, Programming Tags: java matrix code, java matrix programm, java matrix source code, java prograam matrix code, jva prograam matrix mutiply source code by Rana
import java.util.*;
class matrix
{
static Scanner input=new Scanner(System.in);
public static void main(String[] args)
{
//starting matrix programm…
//a matrix example
//a=|2 3| b=|5 6|
// |7 8| |3 2|
//result |2*5+3*3 2*6+3*2|
// |7*5+8*3 7*6+8*2|
//now we need to first input value of row and column
//we need to define row as r and collum as c
//we r now trying to take input by using foor loop
int r,c,k,addMatrix=0;
int ar,ac;
System.out.println(“Please input the row number of matrix a”);
ar=input.nextInt();
System.out.println(“Please input the colum number of matrix a”);
ac=input.nextInt();
int br,bc;
System.out.println(“Please input the row number of matrix b”);
br=input.nextInt();
System.out.println(“Please input the column number of matrix a”);
bc=input.nextInt();
int[][] a=new int[ar][ac];
int[][] b=new int[br][bc];
int[][] result=new int[ar][bc];
while(ac!=br){
System.out.println(“First matrix column and second matrix row need to be eqaul”);
//again taking input from user
System.out.println(“Please input the row number of matrix a again”);
ar=input.nextInt();
System.out.println(“Please input the colum number of matrix a again”);
ac=input.nextInt();
System.out.println(“Please input the row number of matrix b again”);
br=input.nextInt();
System.out.println(“Please input the column number of matrix a again”);
bc=input.nextInt();
}
if(ac==br){
//Input value of “a” matrix
System.out.println(“I nput value of a … u need to input value of 1st row first then second row”);
for(r=0;r<ar;r++){
for(c=0;c<ac;c++){
a[r][c]=input.nextInt();
}
}
for (r = 0; r < ar; r++) {
for (c = 0; c < ac; c++) {
System.out.print(a[r][c]+”\t”);
}
System.out.println(“\n”);
}
//input value of “b” matrix
System.out.println(“I nput value of b … u need to input value of row first”);
for(r=0;r<br;r++){
for(c=0;c<bc;c++){
b[r][c]=input.nextInt();
}
}
for (r = 0; r <br; r++) {
for (c = 0; c <bc; c++) {
System.out.print(b[r][c]+”\t”);
}
System.out.println(“\n”);
}
//multiplication value of matrix
for (r = 0; r <ar; r++) {
for (c = 0; c <bc; c++) {
for (k = 0; k <br; k++) {
addMatrix=addMatrix+a[r][k]*b[k][c];
} //end of k loop
result[r][c]=addMatrix;
addMatrix=0;
}
}
for (r = 0; r < ar; r++) {
for (c = 0; c <bc; c++) {
System.out.print(result[r][c]+”\t”);
}
System.out.println(“\n”);
}
}
}
}
You can only multiply 2 matrix by using this program 🙂
[As this is only source code of the pprogram you need a java compiler to run this program 🙂 ]
31 responses to “Java program source code for multiplying 2 Matrix”
Leave a Reply
You must be logged in to post a comment.
Categories
- Android (24)
- Android Applications (15)
- Android Develop (6)
- Android Custom Rom (2)
- Android Root (6)
- Xposed (1)
- Android Games (1)
- Android Tips (7)
- Education (3)
- Examination Results (2)
- Facebook Tips (14)
- Featured (6)
- Free Internet Trick (13)
- Airtel Free Internet (2)
- BL Free Internet (2)
- Gp Free Internet (4)
- Robi Free Internet (2)
- Freelancing (2)
- Hacking (2)
- Hot (5)
- Java (2)
- Java Development (1)
- Mobile Tips (4)
- Operator News (43)
- Airtel (8)
- Banglalink (3)
- Grameenphone (25)
- Offer & Promotion (1)
- Robi (9)
- Teletalk (1)
- Other (8)
- Programming (6)
- Java Programming (6)
- Sponsored (1)
- Technology Update (1)
- TrickBD Updates (5)
- Web Development (13)
- Alexa Tips (1)
- Domain & Hosting (1)
- Seo (5)
- Wapka (3)
- wwordpress (2)
- Windows (4)
- Windows Games (1)
- Windows Tips (3)
nice
… [Trackback]
[…] Read More: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Informations on that Topic: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Find More Informations here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Informations on that Topic: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Informations on that Topic: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] There you will find 41426 more Infos: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] There you will find 24852 more Infos: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Informations on that Topic: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More Infos here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More Infos here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Find More Informations here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]
… [Trackback]
[…] Read More Infos here: en.trickbd.com/java-program-source-code-for-multiplying-2-matrix/4197 […]